#!/usr/bin/env python
# -*- coding: utf-8 -*-

from web.manager.oracle_manager import OracleManager
from web.models.etf_info import EtfInfo

"""
EtfInfo的dao类
"""


class EtfInfoDao:

    def __init__(self):
        self.db = OracleManager()

    def find_all(self):
        """
        查询所有记录
        """

        self.db.connect()
        _list = self.db.execute_query("select * from etf_info")
        self.db.close()
        etf_info_list = list()
        for model in _list:
            etf_info = EtfInfo()
            etf_info.id_ = model[0]
            etf_info.code_ = model[1]
            etf_info.name_ = model[2]
            etf_info.available = model[3]
            etf_info.tendency_type = model[4]
            etf_info_list.append(etf_info)
        return etf_info_list

    def find_code(self):
        """
        查询所有记录的code_字段
        """

        self.db.connect()
        _list = self.db.execute_query("select code_ from etf_info")
        self.db.close()
        code_list = list()
        for model in _list:
            code_list.append(model[0])
        return code_list